<?php
namespace app\index\model;

use think\Model;
use think\Request;

class Course extends Model{
    public function courselist(){
        $map = [];
        $request = Request::instance();
        //判断是否搜索课程编号
        if($request->has("Id","get")){
            $courseId = $request->get("Id");
            $map["courseId"]=["LIKE","%".$courseId."%"];
        }
        //判断是否搜索课程名
        if($request->has("cName","get")){
            $courseName = $request->get("cName");
            $map["courseName"]=["LIKE","%".$courseName."%"];
        }
        //判断是否搜索任课教师
        if($request->has("uName","get")){
            $userName = $request->get("uName");
            $map["userName"]=["LIKE","%".$userName."%"];
        }
        $data= $this->alias('cos')
                    ->join('tc a','cos.Id = a.C_Id')
                    ->join('user t','a.T_Id = t.Id')
                    ->where($map)
                    ->select();
        // echo $this->getLastsql();
        return $data;
    }

    public function newcourse(){
        $data = $this->limit(1)->order('Id desc') ->select();
        return $data;
    }

    public function addcourse($courseId,$courseName){
        $Data = [
            "courseId" => $courseId,
            "courseName" => $courseName,
        ];
        return $this->insert($Data);
    }

    public function cossign($id){
        $map = [];
        $request = Request::instance();
        //判断是否搜索课程编号
        if($request->has("class","get")){
            $class_Id = $request->get("class");
            $map["class_Id"]=["LIKE","%".$class_Id."%"];
        }

        $data= $this->alias('cos')
                    ->join('cossign a','cos.Id = a.course_Id')
                    ->join('signlist sign','a.sign_Id = sign.Id')
                    ->join('classes cla','a.class_Id = cla.Id')
                    ->where('cos.Id',$id)
                    ->where($map)
                    ->select();
        // echo $this->getLastsql();
        return $data;
    }

    public function stucossign($courseId,$classId){
        $data= $this->alias('cos')
                    ->join('cossign a','cos.Id = a.course_Id')
                    ->join('signlist sign','a.sign_Id = sign.Id')
                    ->join('classes cla','a.class_Id = cla.Id')
                    ->where('cos.Id',$courseId)
                    ->where('a.class_Id',$classId)
                    ->select();
        // echo $this->getLastsql();
        return $data;
    }
}